import socket,time,threading

def client_thread(i):
    server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host="127.0.0.1"
    host="121.43.154.187"
    port=8888
    server.connect((host,port))#连接服务器
    print('已连接')
    num = 1
    server.send("{}:hello".format(i).encode("utf-8"))
    while True:
        data = server.recv(1024).decode("utf-8")
        print('接收的内容：'+ data)
        server.send("{}num:{}".format(i,num).encode("utf-8"))
        num = (num + 1) % 100
        time.sleep(2)
    server.close()

t2 = threading.Thread(target=client_thread, args=(0,))
t1 = threading.Thread(target=client_thread, args=(1,))

t1.start()
# t2.start()

t1.join()
t2.join()



